package com.zj.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Data
@ConfigurationProperties(prefix = "aliyun.oss")   //方案一：自动配置
//@PropertySource("classpath:aliyun-oss.properties")  //方案二
public class OssConfig {
//    @Value("${aliyun.oss.endpoint}")
    private String endpoint;
//    @Value("${aliyun.oss.accessKeyId}")
    private String accessKeyId;
//    @Value("${aliyun.oss.accessKeySecret}")
    private String accessKeySecret;
//    @Value("${aliyun.oss.bucketName}")
    private String bucketName;
//    @Value("${aliyun.oss.urlPrefix}")
    private String urlPrefix;

    @Bean //将OSSClient 注册为 Spring Bean
    public OSS ossClient(){
        return new OSSClientBuilder().build(endpoint,accessKeyId,accessKeySecret);
    }
}
